/*  FantastleX: A Maze/RPG Hybrid Game
Copyleft 2013 Eric Ahnell

Any questions should be directed to the author via email at: products@puttysoftware.com
 */
package com.puttysoftware.fantastlex.creatures.genders;

import com.puttysoftware.commondialogs.CommonDialogs;

public class GenderManager implements GenderConstants {
    private static boolean CACHE_CREATED = false;
    private static Gender[] CACHE;

    public static Gender selectGender() {
        final String[] names = GenderConstants.GENDER_NAMES;
        String dialogResult = null;
        dialogResult = CommonDialogs.showInputDialog("Select a Gender",
                "Create Character", names, names[0]);
        if (dialogResult != null) {
            int index;
            for (index = 0; index < names.length; index++) {
                if (dialogResult.equals(names[index])) {
                    break;
                }
            }
            return GenderManager.getGender(index);
        } else {
            return null;
        }
    }

    public static Gender getGender(int genderID) {
        if (!GenderManager.CACHE_CREATED) {
            // Create cache
            GenderManager.CACHE = new Gender[GenderConstants.GENDERS_COUNT];
            for (int x = 0; x < GenderConstants.GENDERS_COUNT; x++) {
                GenderManager.CACHE[x] = new Gender(x);
            }
            GenderManager.CACHE_CREATED = true;
        }
        return GenderManager.CACHE[genderID];
    }
}
